package org.netEase.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.netEase.dao.zhutizuDao;
import org.netEase.entity.zhuti;
import org.netEase.entity.zhutizu;
import org.netEase.util.BaseDao;

public class zhutizuDaoImpl extends BaseDao implements zhutizuDao {

	@Override
	public List<zhutizu> getbyYid(int Yid) {
		List<zhutizu> list = new ArrayList<>();
		String sql = "select * from zhutizu where Yid = ?";
		ResultSet rs = super.executeQuery(sql,Yid);
		try {
			while (rs.next()) {
				zhutizu zhutizu = new zhutizu();
				zhutizu.setYid(rs.getInt("yid"));
				zhutizu.setZid(rs.getInt("zid"));
				zhutizu.setzName(rs.getString("zName"));
				zhutizu.setZimg(rs.getString("zimg"));
				
				list.add(zhutizu);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				closeAll(rs.getStatement().getConnection(), rs.getStatement(), rs);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return list;
	}
	
/*	public static void main(String[] args) {
		zhutizuDao zhutizuDao = new zhutizuDaoImpl();
		List<zhutizu> list=zhutizuDao.getbyYid(1);
		for (zhutizu zhutizu : list) {
			System.out.println(zhutizu);
		}
	}*/
	@Override
	public List<zhutizu> getbyYid() {
		List<zhutizu> list = new ArrayList<>();
		String sql = "select * from zhutizu";
		ResultSet rs = super.executeQuery(sql);
		try {
			while (rs.next()) {
				zhutizu zhutizu = new zhutizu();
				zhutizu.setYid(rs.getInt("yid"));
				zhutizu.setZid(rs.getInt("zid"));
				zhutizu.setzName(rs.getString("zName"));
				zhutizu.setZimg(rs.getString("zimg"));
				
				list.add(zhutizu);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}finally {
			try {
				closeAll(rs.getStatement().getConnection(), rs.getStatement(), rs);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return list;
	}

}
